export type Role = 'admin' | 'user'

export interface MockUser {
	id: string
	username: string
	password: string
	nickname: string
	avatar?: string
	avator?: string
	role: Role
	rolename: string
	state?: string
	tip?: string
	accessToken?: string
	refreshToken?: string
}

export const mockUsers: MockUser[] = [
	{
		id: '1',
		username: 'admin',
		password: '123456',
		nickname: '管理员',
		role: 'admin',
		rolename: '管理员',
		avatar: `https://api.dicebear.com/7.x/miniavs/svg?seed=10`,
		avator: `https://api.dicebear.com/7.x/miniavs/svg?seed=10`,
		state: 'active',
		tip: '拥有全部操作权限',
		accessToken: 'mock-admin-access-token',
		refreshToken: 'mock-admin-refresh-token'
	},
	{
		id: '2',
		username: 'user',
		password: '123456',
		nickname: '普通用户',
		role: 'user',
		rolename: '普通用户',
		avatar: `https://api.dicebear.com/7.x/miniavs/svg?seed=10`,
		avator: `https://api.dicebear.com/7.x/miniavs/svg?seed=10`,
		state: 'active',
		tip: '仅可使用聊天与AI对话',
		accessToken: 'mock-user-access-token',
		refreshToken: 'mock-user-refresh-token'
	}
]

// 模拟登录接口，返回与现有 LoginModal 期望一致的结构
export function mockLogin(username: string, password: string) {
	const user = mockUsers.find(u => u.username === username && u.password === password)
	if (user) {
		return {
			data: {
				code: 200,
				message: 'success',
				data: {
					accessToken: user.accessToken || `mock-access-${user.role}-${Date.now()}`,
					refreshToken: user.refreshToken || `mock-refresh-${Date.now()}`,
					userInfo: {
						...user,
						// 保证头像与用户名字段存在
						avatar: user.avatar || user.avator || '',
						username: user.username
					}
				}
			}
		}
	}
	return {
		data: {
			code: 401,
			message: '用户名或密码错误'
		}
	}
}